using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Box : MonoBehaviour
{
    public int BoxNum;
    public float HP;
    public GameObject[] itemDrop;
    private int HurtNum;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (HP <= 0)
        {
            float x = Random.Range(1, 100);
            if (x < 5) { GameObject instance = GameObject.Instantiate(itemDrop[0], transform.position, transform.rotation); }
            else if (x > 95) { GameObject instance = GameObject.Instantiate(itemDrop[1], transform.position, transform.rotation); }
            Destroy(gameObject);
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.layer == LayerMask.NameToLayer("Bullet_Player")|| collision.gameObject.layer == LayerMask.NameToLayer("Bullet_Enemy") || collision.gameObject.layer == LayerMask.NameToLayer("Knife"))
        {
                if (collision.GetComponent<bullet>() != null)
                { HurtNum = collision.GetComponent<bullet>().damage; }
                if (collision.GetComponent<bullet2>() != null)
                { HurtNum = collision.GetComponent<bullet2>().damage; }
                HP -= HurtNum;
        }
    }
}
